import { useEffect, useState } from "react";

interface Scroll {
   left: number;
   top: number;
}

const useScroll = (): { scroll: Scroll } => {

   const [scroll, setScroll] = useState<Scroll>({ left: 0, top: 0 });

   const handleScroll = ()=> {
      setScroll({
         left: Math.floor(document.documentElement.scrollLeft),
         top: Math.floor(document.documentElement.scrollTop),
      });

   };

   useEffect(() => {
      document.addEventListener("scroll", handleScroll);
      return () => {
         document.removeEventListener("scroll", handleScroll);
      };
   }, [scroll]);

   return {
      scroll,
   };

};


export default useScroll;
